home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / teco.zip / TECO.C < prev    next >
C/C++ Source or Header  |  1986-07-15  |  4KB  |  161 lines

  1. /*  TECO - Context Editor
  2.  
  3. (C) COPYRIGHT 1986 by Y.N. Miles; ALL RIGHTS RESSERVED
  4.  
  5.     Description:
  6.  
  7.         This program implements a subset of the commands for the
  8.         context editor TECO, which was developed at MIT in the
  9.         early 1960s, and was supported on most of the earlier
  10.         Digital Equipment machines (PDP-8, PDP-10, PDP-11).
  11.         This program was based on the "PDP-11 Teco User's Guide",
  12.         by Digital Equipment, 1980, Order Number DEC-11-UTECA-B-D,
  13.         and was written by the author in utter *PANIC* when it was
  14.         realized that Digital Equipment was quietly dropping the
  15.         support for TECO in its MicroVax family of computers.
  16.         By rewriting TECO in the popular portable programming
  17.         language "C", the author hopes to be able to continue
  18.         using TECO independent of Digital Equipment's corporate
  19.         policies, and also hopes to be able to make it available
  20.         to the many users who have been unfortunate enough not
  21.         to have access to an Operating System which had a working
  22.         version of the best non-visual text editor around...
  23.  
  24.     Instructions:
  25.  
  26.         This version is based on the "PDP-11 Teco Users Guide",
  27.         published 1980 as order no "DEC-11-UTECA-B-D", from:
  28.  
  29.             TECO SIG,
  30.             c/o DECUS, MR2-3/E55
  31.             One Iron Way
  32.             Marlboro, MA 01752
  33.  
  34.     Language:
  35.  
  36.         Microsoft "C" version 3.00
  37.  
  38.     License Agreement:
  39.  
  40.         All users are granted a limited license to make copies
  41.         of this program, and to distribute them at will for
  42.         non-commercial use, provided no fee or consideration
  43.         is received without the express consent of the Author
  44.  
  45.             Y.N. Miles
  46.             TRIUMF, U.B.C.
  47.             4004 Wesbrook Mall
  48.             Vancouver, B.C.
  49.             Canada, V6T 2A3
  50.  
  51.             Phone (604) 222-1047
  52. */
  53. #include <ctype.h>
  54. #include <fcntl.h>
  55. #include <io.h>
  56. #include <signal.h>
  57. #include <stdio.h>
  58. #include <string.h>
  59.  
  60. char bkname[128],bkpath[128],bktype[5]; /* Backup name,path,type */
  61. char inname[128],inpath[128],intype[5]; /* Input  name,path,type */
  62. char otname[128],otpath[128],ottype[5]; /* Output name,path,type */
  63.  
  64. FILE *in; /* Input  stream */
  65. FILE *ot; /* Output stream */
  66.  
  67. char buffer[32001];/* Work buffer area */
  68. int  bufptr=0     ;/* --> last in bfr  */
  69. int  bufptx=0     ;/* --> char in bfr  */
  70. int  bufsiz=32000 ;/* Size of work buf */
  71.  
  72. char getbuf[8193]; /* User keyboard buffer */
  73. int  getptr=0    ; /* --> last in key bfr  */
  74. int  getptx=0    ; /* --> char in key bfr  */
  75. int  getsiz=8192 ; /* Characters in getbuf */
  76.  
  77. int adverb    ;  /* Qualifier  for  verb */
  78. int cancel    ;  /* Non-zero if ^O typed */
  79. int number    ;  /* Value    for command */
  80. int verb    ;  /* Name     of  command */
  81.  
  82. main(argc,argv) /* Excized Teco Editor */
  83. int argc;
  84. char *argv[];
  85. {
  86. #include "teco.h"
  87.  
  88.     FILE *fopen();
  89.     int abort();
  90.     char *p,*q;
  91.  
  92.     fprintf(stderr,"TECO ver X1.04\n");
  93.  
  94.     if (argc ==1 ) {
  95.         fprintf(stderr,"?NFI, No file for input\n\7");
  96.                 exit(1);
  97.     } else {
  98.         if (argc !=2 ) {
  99.             fprintf(stderr,"? What does '%s",strupr(argv[2]));
  100.             fprintf(stderr,"' mean ?\n\7");
  101.             exit(1);
  102.             }
  103.         }
  104.     p=strchr(argv[1],'=');
  105.     if (!p) {
  106.         strcpy(inname,strupr(argv[1]));
  107.         q=strrchr(inname,'.');
  108.         if (!q) strcat(inname,".");
  109.         q=strrchr(inname,'.');
  110.         strncpy(intype,q,4);
  111.         *q='\0';
  112.         strcpy(inpath,inname);
  113.         strcat(inpath,intype);
  114.         strcpy(otpath,inname);
  115.         strcat(otpath,".TMP");
  116.     } else {
  117.         strcpy(inname,strupr(p+1));
  118.         q=strrchr(inname,'.');
  119.         if (!q) strcat(inname,".");
  120.         q=strrchr(inname,'.');
  121.         strncpy(intype,q,4);
  122.         *q='\0';
  123.         strcpy(inpath,inname);
  124.         strcat(inpath,intype);
  125.         strcpy(otname,strupr(argv[1]));
  126.         q=strchr(otname,'=');
  127.         *q='\0';
  128.         q=strrchr(otname,'.');
  129.         if (!q) strcat(otname,".");
  130.         q=strrchr(otname,'.');
  131.         strncpy(ottype,q,4);
  132.         *q='\0';
  133.         strcpy(otpath,otname);
  134.         strcat(otpath,ottype);
  135.             }
  136.     if ((in = fopen(inpath,"r")) == NULL) {
  137.             fprintf(stderr,"?FNF, File not found '%s'\n\7",inpath);
  138.             exit(1);
  139.         }
  140.     setmode(fileno(in),O_BINARY);
  141.     if ((ot = fopen(otpath,"w")) == NULL) {
  142.             fprintf(stderr,"?FNC, File not created '%s'\n\7",otpath);
  143.             exit(1);
  144.         }
  145.     setmode(fileno(ot),O_BINARY);
  146.  
  147.     signal(SIGINT,abort);        /* Enable trap */
  148.     work();                /* Do the teco */
  149.     signal(SIGINT,SIG_DFL);        /* Disabl trap */
  150.  
  151.     fclose(in);
  152.     fclose(ot);
  153.     if (!p) {
  154.         strcpy(bkpath,inname);
  155.         strcat(bkpath,".BAK");
  156.         unlink(bkpath)       ; /* Ignore error */
  157.         rename(bkpath,inpath);
  158.         rename(inpath,otpath);
  159.     }
  160. }
  161.